package editAir.buildEdit
{
	import _Pan3D.core.MathCore;
	
	import _me.Scene_data;
	
	import com.adobe.utils.PerspectiveMatrix3D;
	
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display3D.Context3D;
	import flash.display3D.Context3DBlendFactor;
	import flash.display3D.Context3DCompareMode;
	import flash.display3D.Context3DProgramType;
	import flash.display3D.Context3DTextureFormat;
	import flash.display3D.Context3DTriangleFace;
	
	import newPan3d.content.build.BuildLevel;
	import newPan3d.content.ground.GroundLevel;
	import newPan3d.content.ground.map.MapClass;
	import newPan3d.content.scene.SceneMenager;

	public class BuildEditScene3D
	{
		public var _groundView:GroundLevel
		public var _buildView:BuildEditLevel
		public var _projMatrix:PerspectiveMatrix3D;
		public var _keyControl:BuildEditKeyControl=new BuildEditKeyControl;
		[Embed(source="../_File/beijing1/panpanpan.jpg")]
		private static var newDengGuang:Class;
		public function BuildEditScene3D()
		{
		}
		private  function makeShenduText():void
		{
			
			//初始化地面环境光贴图
			var context3D:Context3D=Scene_data.context3D
			var tempBmp:BitmapData=Bitmap(new newDengGuang()).bitmapData;
		//	Scene_data.shenduText=context3D.createTexture(tempBmp.width,tempBmp.height, Context3DTextureFormat.BGRA,true);
		//	Scene_data.shenduText.uploadFromBitmapData(tempBmp);
		
			
			
			//下面是定义为百色的基础色;
			//Scene_data.groundLightText=context3D.createTexture(64, 64, Context3DTextureFormat.BGRA, true);
			//Scene_data.groundLightText.uploadFromBitmapData(new BitmapData(64, 64, true, 0x00ffffff));
			
		}
		public function initData():void
		{
			SceneMenager.initData();
			MapClass.initData();
			Scene_data.funToScanShodar=getShadowBitMapData; //加载完所有资源，就扫描阴影
			makeScene();
			makeShenduText()
			_keyControl.init(Scene_data.stage);
	
		}
		
		
		public function makeScene():void
		{
			_groundView=new GroundLevel();
			_buildView=new BuildEditLevel();

			
			EditManage.buildView=_buildView;
		}
		
		public function upData():void
		{
			if (!Scene_data.ready)
				return;
			//Scene_data.groundLightText=Scene_data.sceneLightText
			Scene_data.sceneLightText=Scene_data.groundLightText
			var context3D:Context3D=Scene_data.context3D;
			
			
			MathCore._catch_cam(Scene_data.cam3D, Scene_data.focus3D);
			context3D.clear(0, 0, 0, 1);
			_projMatrix=new PerspectiveMatrix3D();
			_projMatrix.perspectiveFieldOfViewLH(1, 1, 0.1, 9000);
			context3D.setProgramConstantsFromMatrix(Context3DProgramType.VERTEX, 0, _projMatrix, true);
			context3D.setBlendFactors(Context3DBlendFactor.ONE, Context3DBlendFactor.ZERO);
			context3D.setDepthTest(true, Context3DCompareMode.LESS);
			context3D.setCulling(Context3DTriangleFace.NONE);
			_groundView.upData();
			_buildView.upData();
			context3D.present();


		}
		
		public var haveShadow:Boolean=false;
		
		public function getShadowBitMapData():void
		{
				return;
		}
		
		public function stageResize():void
		{
			Scene_data.cam3D.fovw=Scene_data.stageWidth;
			Scene_data.cam3D.fovh=Scene_data.stageHeight;
			var context3D:Context3D=Scene_data.context3D;
			context3D.configureBackBuffer(Scene_data.stageWidth, Scene_data.stageHeight, 0, true);
		}
	}
}